<?php
require ('../classes/HTMLManager.class.php');
require ('../classes/GalleryManager.class.php');
require ('../classes/CinemaManager.class.php');
require ('../classes/ArticleManager.class.php');

define (ACTION_LAST_GALLERIES, 'last');
define (ACTION_PATH, 'path');
define (ACTION_GALLERY, 'gallery');
    
    /*echo $_GET['type'] . '|';
    echo $_GET['path'] . '|';
    echo $_GET['id']; */

    $gm = new GalleryManager();
    if (isset($_GET['year'])) {
        $galleries = $gm->get_galleries_by_year($_GET['year']);
    } else if (isset($_GET['type'])) {
        if ($_GET['type'] == ACTION_LAST_GALLERIES) {
            $galleries = $gm->get_last_galleries();
        } else if ($_GET['type'] == ACTION_PATH) {
            if (isset($_GET['path'])) {
                $fs = explode("/", trim($_GET['path'], "/"));
                if($gm->check_folders_hierarchy($fs)) {
                    $folders = $gm->get_subfolders($fs[count($fs) - 1]);
                    $galleries = $gm->get_galleries_in_folder($fs[count($fs) - 1]);
                    
                    $fd = array();
                    foreach ($fs as $fn) {
                        array_push($fd, $gm->get_folder_description($fn));
                    }
                    //$current_folder_description = $gm->get_folder_description($fs[count($fs) - 1]);
                    $error_path = false;
                } else {
                    $error_path = true;
                }
            }
        } else if ($_GET['type'] == ACTION_GALLERY) {
            if (isset($_GET['path'])) {
                $fs = explode("/", trim($_GET['path'], "/"));
                if($gm->check_folders_hierarchy($fs)) {
                    if (isset($_GET['id'])) {
                        if ($gm->check_folder_gallery($_GET['id'], $fs[count($fs) - 1])) {
                            $gallery = $gm->get_gallery_by_id($_GET['id']);
                            $gm->get_photos($gallery);
                            $error_path = false;
                        } else {
                            $error_path = true;
                        }
                    } else {
                        $error_path = true;
                    }
                } else {
                    $error_path = true;
                }
            }
        }
    } else {
        $folders = $gm->get_root_folders();
    }
    include ('gallery.view.php');
?>
